package starter.context;

import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import com.bowlong.util.MapEx;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class App extends JSONContext {
	public static final GameContext game = new GameContext();
	// public static final RedisContext redis = new RedisContext();
	public static final MySqlContext ds = new MySqlContext("ds|game");

	// public static final MySqlContext design = new MySqlContext("ds|design");

	public static int serverID() { // 服务器id
		return game.id;
	}

	// 取得数据源
	public static DataSource ds() {
		return ds.dataSource;
	}

	public static String getTableListIconUrl() {
		return MapEx.getString(app(), "TableListIconUrl");
	}

	public static String getGenerateUrl() {
		return MapEx.getString(app(), "GENERATE_URL");
	}

	public static String getResourcesUrl() {
		return MapEx.getString(app(), "RESOURCES_URL");
	}

	public static int getInitUserCount() {
		return MapEx.getInt(app(), "INIT_USER_COUNT");
	}

	public static boolean openLog4j() {
		return MapEx.getBoolean(app(), "log4j");
	}

	// 取得初始用户信息
	public static Map getInitUserInfo() {
		return initUser();
	}

	public static List getInitUserBuildings() {
		return MapEx.getList(initUser(), "buildings");
	}

	public static List getInitUserObstacles() {
		return MapEx.getList(initUser(), "obstacles");
	}

	public static List getInitUserTraps() {
		return MapEx.getList(initUser(), "traps");
	}

	public static List getInitUserDecos() {
		return MapEx.getList(initUser(), "decos");
	}

	public static Map<String, Object> initUser() {
		if (INITUSER == null) {
			INITUSER = (Map<String, Object>) ctx().get("InitUser");
		}
		return INITUSER;
	}

	static Map<String, Object> APP = null;
	static Map<String, Object> INITUSER = null;

	public static Map<String, Object> app() {
		if (APP == null)
			APP = (Map<String, Object>) ctx().get("app");
		return APP;
	}

}
